//
//  YYBaseView.swift
//  新浪微博
//
//  Created by fdq on 16/7/19.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit

class YYBaseView: UIView {
	
	var closure : (()->())?

	override init(frame: CGRect) {
		
		super.init(frame: frame)
		setupUI()
	}

	required init?(coder aDecoder: NSCoder) {
	    fatalError("init(coder:) has not been implemented")
	}
	//为每个界面提供方法,每个界面显示的内容不一样
	func setupMainViewInfo(title: String?,imageName:String?){
		
		if let tit = title,let imgName = imageName{
			
			centerImg.image = UIImage(named: imgName)
			label.text = tit
			cirleImg.hidden = true
			
		}else{
			rotateCircle()

		}
		
	}
	//圆形图旋转
	func rotateCircle(){
		
		let animation1 = CABasicAnimation(keyPath: "transform.rotation")
		
		animation1.toValue = M_PI * 2
		animation1.duration = 10
		animation1.repeatCount = MAXFLOAT
		animation1.removedOnCompletion = false
		cirleImg.layer.addAnimation(animation1, forKey: nil)
		
	}

	//按钮监听方法
	func clickLoginBtn(){
		
		closure?()
	}
	

	//设置中间图片和label
	func setupUI(){
		
		backgroundColor = UIColor(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)
		addSubview(cirleImg)
		addSubview(centerImg)
		addSubview(maskImg)
		addSubview(label)
		addSubview(regButton)
		addSubview(loginButton)
		
		cirleImg.snp_makeConstraints { (make) -> Void in
			make.center.equalTo(self.center)
		}
		centerImg.snp_makeConstraints { (make) -> Void in
			make.center.equalTo(self.center)
		}
		maskImg.snp_makeConstraints { (make) -> Void in
			make.center.equalTo(self.center)
		}
		label.snp_makeConstraints { (make) -> Void in
			make.centerX.equalTo(self.snp_centerX)
			make.size.equalTo(CGSize(width: 230, height: 36))
			make.top.equalTo(maskImg.snp_bottom).offset(16)

		}
		
		loginButton.snp_makeConstraints { (make) -> Void in
			make.top.equalTo(label.snp_bottom).offset(10)
			make.leading.equalTo(label.snp_leading)
			make.size.equalTo(CGSize(width: 100, height: 36))
		}
		regButton.snp_makeConstraints { (make) -> Void in
			make.top.equalTo(label.snp_bottom).offset(10)
			make.trailing.equalTo(label.snp_trailing)
			make.size.equalTo(CGSize(width: 100, height: 36))
		}
		
	}
	
	//MARK - 懒加载控件
	//圆形图片
	lazy var cirleImg :UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
	//中间图片
	lazy var centerImg :UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
	//遮照图片
	lazy var maskImg :UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
	//文字内容
	lazy var label : UILabel = {
		let lab = UILabel()
		lab.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
		lab.font = UIFont.systemFontOfSize(14)
		lab.textColor = UIColor.grayColor()
		lab.numberOfLines = 0
		return lab
	}()
	//按钮
	lazy var loginButton : UIButton = {
		let loginBtn = UIButton()
		loginBtn.addTarget(self, action: "clickLoginBtn", forControlEvents: UIControlEvents.TouchUpInside)
		loginBtn.setTitle("登录", forState: UIControlState.Normal)
		loginBtn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
		loginBtn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
		return loginBtn
	}()
	//注册
	lazy var regButton : UIButton = {
		let regButton = UIButton()
		regButton.addTarget(self, action: "clickLoginBtn", forControlEvents: UIControlEvents.TouchUpInside)
		regButton.setTitle("注册", forState: UIControlState.Normal)
		regButton.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
		regButton.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
		return regButton
	}()
	
}
